//
//@File    :	13.14_dma.h
//@Time    :	2022/01/19 11:56:47
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	inheritance and dynamice memory allocation
//

#ifndef DMA_H_
#define DMA_H_
#include <iostream>

//Base Class Using DMA
class baseDMA
{
private:
    char *label;
    int rating;

public:
    baseDMA(const char *l = "null", int r = 0);
    baseDMA(const baseDMA &rs);            //复制构造函数
    virtual ~baseDMA();                    //析构函数
    baseDMA &operator=(const baseDMA &rs); //重载赋值运算符
    friend std::ostream &operator<<(std::ostream &os, const baseDMA &rs);
};
//派生类不适用动态内存分配
//derived class without DMA
//no destructor needed
//uses implicit copy constructor
//uses implicit assignment operator
class lacksDMA : public baseDMA
{
private:
    enum
    {
        COL_LEN = 40
    };
    char color[COL_LEN];

public:
    lacksDMA(const char *c = "balck", const char *l = "null", int r = 0);
    lacksDMA(const char *c, const baseDMA &rs);
    friend std::ostream &operator<<(std::ostream &os, const lacksDMA &ls);
};
//派生类使用动态内存分配
//derived class with DMA
class hasDMA : public baseDMA
{
private:
    char *style;

public:
    hasDMA(const char *s = "none", const char *l = "null", int r = 0);
    hasDMA(const char *s, const baseDMA &rs);
    hasDMA(const hasDMA &hs);
    ~hasDMA();
    hasDMA &operator=(const hasDMA &hs);
    friend std::ostream &operator<<(std::ostream &os, const hasDMA &hs);
};
#endif // DMA_H_